package com.atao.example.lambda04;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 阿涛
 * @date 2021-03-06
 */
public class Test {

    private static void newThread(Runnable runnable) {
        new Thread(runnable).start();
    }

    public static void main(String[] args) {
        final Date date = new Date();
        final Map<Integer, Object> map = new HashMap<>();
        map.put(1, 2);
        //todo 普通方式
        newThread(new Runnable() {
            @Override
            public void run() {
                date.setTime(1000000);
                map.put(1,3);
                System.out.println("匿名内部类当前线程-" + Thread.currentThread().getName());
            }
        });
        //todo lambda表达式
        newThread(() -> {
            date.setTime(1000000);
            map.put(1,4);
            map.put(1,new Date());
            System.out.println("匿名内部类当前线程-" + Thread.currentThread().getName());
        });
        //todo lambda表达式简化
        newThread(() -> System.out.println("lambda表达式简化当前线程-" + Thread.currentThread().getName()));
    }

}
